#pragma once

#include<iostream>

class Task
{
public:
    // 默认构造
    Task(int left = 0, int right = 0, char op = '+')
        : _left(left)
        , _right(right)
        , _op(op)
    {
    }

    void operator()()
    {
        switch (_op)
        {
        case '+':
            _ret = _left + _right;
            break;
        case '-':
            _ret = _left - _right;
            break;
        case '*':
            _ret = _left * _right;
            break;
        case '/':  
            if(_right == 0) //处理右操作数为0的情况
            {
                _exit_code = -1;
            }
            else
            {
                _ret = _left / _right;
            }
            break;
        case '%':
            if(_right == 0) //处理右操作数为0的情况
            {
                _exit_code = -2;
            }
            else
            {
                _ret = _left % _right;
            }
            break;
        }
    }

    void showExp()
    {
        std::cout << _left << " " << _op << " " << _right << " = ?" << std::endl;
    }

    void showRet()
    {
        std::cout << "ret = " << _ret << " " << "exitcode = " << _exit_code << std::endl;
    }

private:
    int _left;  // 左操作数
    int _right; // 右操作数
    char _op;   // 运算符

    int _ret = 0;       // 计算结果
    int _exit_code = 0; // 退出码,0为正常退出
};